package com.ucode.hrm.service;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ucode.hrm.mapper.HrmJobPostMapper;
import com.ucode.model.hrm.HrmJobPost;
import com.ucode.model.hrm.enums.HrmSysResultCodeEnum;
import com.ucode.springboot.starter.mybatis.core.base.BaseService;
import com.ucode.tool.base.enums.GlobalResultCodeEnum;
import com.ucode.tool.exception.UcodeServiceException;
import com.ucode.tool.util.CollectionUtils;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * 招聘岗位 Service
 * @Author: liliang
 * @Date: 2025/6/1 14:37
 * @Version: 1.0
 */
public interface HrmJobPostService extends BaseService<Long, HrmJobPost, HrmJobPostMapper> {
    default Map<Long, HrmJobPost> getMap(Collection<Long> ids) {
        return CollUtil.isEmpty(ids) ? new HashMap() : CollectionUtils.convertMap(this.selectByPrimaryKeys(ids), HrmJobPost::getId);
    }

    /**
     * 验证是否合法并返回
     * @param id
     * @return
     */
    default HrmJobPost validate(Long id){
        if(ObjectUtil.isNull(id) )
            throw new UcodeServiceException(GlobalResultCodeEnum.VALIDATE_FAILED);
        //验证数据是否存在
        HrmJobPost brand = this.selectByPrimaryKey(id);
        if(ObjectUtil.isNull(brand) || brand.getDeltag()){
            throw new UcodeServiceException(HrmSysResultCodeEnum.JOB_POST_NOT_EXISTS);
        }
        return brand;
    }

}
